//JS的对象
/*var Person = {
	eat : function(){
		console.log('执行吃的方法');
	},
	sleep : function(){
		console.log('执行睡觉的方法');
	},
	success : function(){
		console.log('成功啦~');
	}
};

Person.eat();//调用
*/

//JS的原型链和继承
/*Persons.prototype = {
	name: 'lyq',
	age: 20
}

function Persons() {

};
*/
/*Person.prototype = {
	age : 18,
	home : ['zigong','shanghai'],
	eat : function(){
		console.log('我能吃东西');
	}
};
*/

/*Person.prototype = new Persons();
Person.prototype.constructor = Person;
Person.prototype.eat = function() {console.log('我能吃东西')};
Person.prototype.age = 18;
Person.prototype.getAge = function(){return this.age};
Person.prototype.setAge = function(age){return this.age = age};

function Person() {

};

(function() {
	var person = new Person();
	console.log(person.age);
	console.log(person.eat());
	console.log(person.name);
	console.log(person.setAge(30));
	console.log(person.getAge());
	console.log(person.age);
})();*/



//JS的多态
/*class People{
	constructor(name,age) {
	    this.name = name;
	    this.age = age;
	}

}

class A extends People{
	constructor(name,age) {
		super(name,age);    
	}
	
	speak(){
		alert('我能说话');
	}
}

let a = new A('lyq',20);
a.speak();*/


//JS的面试题
//打车时，车有车牌号和名称，有快车和慢车，快车1公里2元，慢车1公里1元，行程开始，显示车的信息，形成结束显示金额
class Car{
	constructor(name,number) {
	    this.name = name;
	    this.number = number;
	}	
}

class fastCar extends Car{
	constructor(name,number){
		super(name,number)
		this.price = 2
	}
}

class slowCar extends Car{
	constructor(name,number){
		super(name,number)
		this.price = 1
	}
}

class CarFun{
	constructor(car,road) {
	    this.car = car;
	    this.road = road;
	}
	start(){
		console.log(`车辆信息是${this.car.name},车牌号为${this.car.number}`);
	}
	end(){
		console.log(`打车金额为${this.car.price * this.road}`)
	}
	create(){
		return new Car('奥迪','渝A66666');
	}
}

//单例模式静态方法
Car.getInstance = (function(){
	let instance
	return function(){
		if(!instance){
			instance = new Car('兰博基尼','川C12345');	
		}
		return instance;
	}
})();



let car = new fastCar('五菱宏光','京A88888');
let drice = new CarFun(car,10);
drice.start();
drice.end();

//单例模式
let singleCar = Car.getInstance();
console.log('单例模式+'+singleCar.name);

//JS对象化
var fun = {
	goto : function(road){
		return new CarFun(new fastCar('宝马X6','川C88888'),road);
	}
}

//ES6工厂模式
function goto(road){
	return new CarFun(new fastCar('宝马X6','川C88888'),road);
}
